package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.HistoryOrdersPageQueryDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    /**
     * 添加订单
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 根据订单id修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 分页查询订单, (历史订单查询)
     * @param orders
     * @return
     */
    @Select("select * from orders where user_id = #{userId}")
    Page<Orders> pageQuery(Orders orders);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getDetail(Long id);

    /**
     * 根据id取消订单
     * @param orders
     */
    @Update("update orders set status = #{status} where id = #{id}")
    void cancel(Orders orders);

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status = #{status}")
    Integer statistics(Integer status);

    /**
     * 根据订单状态和下单时间查询订单
     * @param pendingPayment
     * @param time
     * @return
     */
    @Select("select * from orders where order_time < #{time} and status = #{pendingPayment}")
    List<Orders> getByStatusAndOrdertimeLT(Integer pendingPayment, LocalDateTime time);


}
